<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>嘉童游乐中心-销售关联会员</title>
<jsp:include page="/common/commonCss.jsp" />
<jsp:include page="/common/commonJs.jsp" />
<script type="text/javascript">
	var memId;
	var name = '';
	var id = '';

	$(document).ready(function() {

		initTab("salesForm");
	});

	function initTab(formId) {
		var fkSales = document.getElementById("sales").value;
		document.getElementById("hiddenFkSales").value = fkSales;
		var form = $("#" + formId);
		var pagebean = new PageBean(form);
		pagebean.setTableId("salesTable");
		pagebean.setCallback(initTable);
		pagebean.setFootId("pagefoot");
		setPagebeanObj(pagebean);
		pagebean.doPage();

	}

	function initTable(data) {
		if (data == null) {
			return;
		}
		$.each(
						data,
						function(ind, obj) {
							var msg ='';
							var memType = obj.memType;
							var status = obj.status;
							var isVip = obj.isVip;
							var age = obj.age;
							var pkMemId = obj.pkMemId;
							var prdName = obj.prdName;
							if (prdName == null) {
								prdName = '';
							}
							if (age == null) {
								age = '';
							}
							if (memType == 1) {
								memType = "是";
							}
							if (memType == 2||memType == 3) {
								memType = "否";
							}
							
							if (status == 1) {
								status = "未激活";
							}
							if (status == 2) {
								status = "有效";
							}
							if (status == 3) {
								status = "过期";
							}
							if (status == 4) {
								status = "停卡";
							}
							if (status == 5) {
								status = "新建";
							}
							if (status == null) {
								status = "";
							}
							if (isVip == 0) {
								isVip = "否";
							}
							if (isVip == 1) {
								isVip = "是";
							}
							var htm = "<tr>";
							htm += "<td>"
									+ "<input type='checkbox' class='mr5' name='box' id='box1'  value='"+pkMemId+"'>"
									+ "</td>";
							var memName = obj.memName;
										if(memName !=null && memName.length > 8 )
											{
												msg = memName.substr(0,8) + "...";
											}
											else if(memName == null)
											{
												msg = "";
											}
											else
											{
												msg = memName;
											}
							htm += "<td>" + obj.salesName + "</td>";
							htm += "<td>" + msg + "</td>";
							htm += "<td>" + memType + "</td>";
							htm += "<td>" + obj.pkMemId + "</td>";
							htm += "<td>" + status + "</td>";
							htm += "<td>" + obj.sex + "</td>";
							htm += "<td>" + age + "</td>";
							htm += "<td>" + obj.countryDesc + "</td>";
							htm += "<td>" + isVip + "</td>";
							htm += "<td>" + prdName + "</td>";
							htm += "<td>"
									+ "<input type='button' value='更换销售' class='btn_l' onclick=\"openx('"
									+ pkMemId + "','" + obj.salesName + "')\">"
									+ "</td></tr>";
							$("#salesTable").find("tr:eq(" + ind + ")").after(
									htm);
						});
		$("#selectAll").attr("checked", false);
	}
	function openx(pkMemId, salesName) {
		clean();
		memId = pkMemId;
		name = salesName;
		$("#name2").html(name);
		$('#qq').window('open');
	}

	function openq() {
		name = "";
		$("[name = box]:checkbox").each(function() {
			if ($(this).attr("checked") == "checked") {
				var sName = $(this).parent().parent().find("td:eq(1)").html();
				var str = name.split(',');
				var length = str.length;
				for (var i = 0; i < length; i++) {
					if (str[i] == sName) {
						return;
					}
				}
				name += sName + ',';
			}
		});
		if(name != ""){
			name = name.substring(0, name.length-1);
		}
		var trueFlag = true;
		if (name == "") {
			alertWarning("请选择一条记录！");
			trueFlag = false;
			return;
		}

		if (trueFlag) {
			$("#name1").html(name);
			$("#q").window('open');
		}
	}

	function selectSales(formId) {
		$("#" + formId + " input:hidden[name='pageNo']").val(1);
		initTab(formId);
	}
	//更改销售
	function updateSales() {
		var fkSales = $("#sales2").val();
		var trueFlag = true;
		if (fkSales == "") {
			alertWarning("请选择销售");
			document.getElementById("sales2").value = "";
			trueFlag = false;
			return;
		}
		var r = confirm("确定修改么");
		if (r && trueFlag) {
			$.ajax({
				url : '${basepath}update.shtml',
				data : {
					"fkMemId" : memId,
					"fkSales" : fkSales
				},
				dateType : "text",
				async : false,
				success : function(result) {
					if (result == "success") {
						alertInfo($common_edit_success);
						initTab("salesForm");
						clean();
					}
				},
				error : function(XMLHttpRequest) {
					 ajaxError(XMLHttpRequest);
					}
			});
		}
	}
	//批量更改销售
	$(function() {
		$("#selectAll").bind("click", function() {
			doChecked($(this));
		});
		$("#updateBatch").bind("click", function() {
				id='';
			var fkSales = $("#sales1").val();
			var trueFlag = true;

			var str = document.getElementsByName("box");
			var length = str.length;
			for (var i = 0; i < length; i++) {
				if (str[i].checked) {
					id = id + str[i].value + ",";
				}
			}
			if (fkSales == "") {
				alertWarning("请选择销售");
				document.getElementById("sales1").value = "";
				trueFlag = false;
				return;
			}
			if (trueFlag) {
				$.ajax({
					url : '${basepath}updateBatch.shtml',
					data : {"id":id,"fkSales":fkSales},
					datetype : "text",
					async : false,
					success : function(result) {
						if (result == "success") {
							alertInfo($common_edit_success);
							initTab("salesForm");

							clean();
						}
					},
					error : function(XMLHttpRequest) {
						 ajaxError(XMLHttpRequest);
						}
				});

			}
		});
	});

	function clean() {
		document.getElementById("name1").value = '';
		document.getElementById("name2").value = '';
		$("#selectAll").attr("checked", false);
		$("[name = box]:checkbox").attr("checked", false);
		$('#q').window('close');
		$('#qq').window('close');
	}

	function doChecked(o) {
		$("[name = box]:checkbox").attr("checked",
				o.attr("checked") == 'checked');
	}
</script>
</head>
<body class="bg">
	<div class="content m_auto">
		<div class="content_l mt10">
			<ul>
				    	<shiro:hasPermission name="authority/role/home.shtml">
         <li><a href="${basePath}authority/role/home.shtml"><i class="nav_icon_u"></i><br>角色管理</a></li>
           </shiro:hasPermission>
           <shiro:hasPermission name="authority/user/home.shtml">
            <li><a href="${basePath}authority/user/home.shtml"><i class="nav_icon_t"></i><br>用户管理</a></li>
           </shiro:hasPermission>
           <shiro:hasPermission name="SalesRelation/mem.shtml">
            <li  class="content_hover"><a href="${basePath}SalesRelation/mem.shtml"><i class="nav_icon_s"></i><br>销售关联会员</a></li>
            </shiro:hasPermission>
            <shiro:hasPermission name="ParRoomDetail/ParRoom.shtml">
            <li><a href="${basePath}ParRoomDetail/ParRoom.shtml"><i class="nav_icon_r"></i><br>房间管理</a></li>
           </shiro:hasPermission>
           <shiro:hasPermission name="SysBarCode/system.shtml">
            <li><a href="${basePath }SysBarCode/system.shtml"><i class="nav_icon_q"></i><br>条码维护</a></li>
            </shiro:hasPermission>
            <shiro:hasPermission name="WfmAuthorize/toShenP.shtml">
            <li><a href="${basePath}WfmAuthorize/toShenP.shtml"><i class="nav_icon_s"></i><br>审批转授权</a></li>
            </shiro:hasPermission>
            <shiro:hasPermission name="holiday/sysHoliday.shtml">
            <li><a href="${basePath}holiday/sysHoliday.shtml"><i class="nav_icon_q"></i><br>节假日管理</a></li>
            </shiro:hasPermission>
       
			</ul>
		</div>
		<div class="content_r mt10">
			<!---- 内容 --->
			<div class="p20">
				<div class="file_single_dl">
					<dl>
						<dd>
							<label>销售姓名：</label>
							<!----select--->
							<div class="uboxstyle">
								<select name="sales" id="sales">
									<option value="">全部</option>
									<c:forEach items="${listuserPar}" var="listuserPar">
										<option value="${listuserPar.pkUsrId}">${listuserPar.usrName}</option>
									</c:forEach>
								</select>
							</div>
							<!----select--->
						</dd>
						<dd>
							<input type="button" class="btn ml10" value="查询"
								onclick="selectSales('salesForm')"><input type="button"
								class="btn ml10" value="批量更换销售" onclick="openq()">
						</dd>
					</dl>
				</div>

				<form action="${basePath}SalesRelation/sales.shtml" method="post"
					id="salesForm">
					<input type="hidden" name="pageNo" value="1"> <input
						type="hidden" name="pageSize" value="10"> <input
						type="hidden" name="fkSales" id="hiddenFkSales">
				</form>


				<table class="table" id="salesTable">
					<tr>
						<th><input type="checkbox" class="mr5" id="selectAll">选择</th>
						<th>销售姓名</th>
						<th>姓名</th>
						<th>是否会员</th>
						<th>会员#</th>
						<th>状态</th>
						<th>性别</th>
						<th>年龄</th>
						<th>国籍</th>
						<th>VIP</th>
						<th>会员类型</th>
						<th>操作</th>
					</tr>

				</table>
				<!----翻页----->

				<div class="page fr m10" id="pagefoot"></div>
				<!----翻页----->
			</div>
			<!---- 内容 --->
		</div>
	</div>





	<!---弹出层--->
	<div id="q" class="easyui-window" title="批量更换销售"
		data-options="modal:true,closed:true,iconCls:'icon-save'"
		style="width: 600px; height: 300px; position: relative;">
		<ul class="w360_c yonh_x_ul">
			<li><label>原销售：</label><span id="name1"></span></li>
			<li><label>销售姓名：</label> <!----select--->
				<div class="uboxstyle">
					<select name="sales1" id="sales1">
						<option value=""></option>
						<c:forEach items="${listuserPar}" var="listuserPar">
							<option value="${listuserPar.pkUsrId}">${listuserPar.usrName}</option>
						</c:forEach>
					</select>
				</div> <!----select---></li>
		</ul>
		<div class="btm_btn btm_bg">
			<dl>
				<dd>
					<input type="button" class="btn" id="updateBatch" value="确定">
				</dd>
				<dd>
					<input type="button" class="btn" onClick="clean()" value="返回">
				</dd>
			</dl>
		</div>
	</div>
	<!---弹出层--->
	<!---弹出层--->
	<div id="qq" class="easyui-window" title="更换销售"
		data-options="modal:true,closed:true,iconCls:'icon-save'"
		style="width: 600px; height: 300px; position: relative;">
		<ul class="w360_c yonh_x_ul">
			<li id="nameLi"><label>原销售：</label><span id="name2"></span></li>
			<li><label>销售姓名：</label> <!----select--->
				<div class="uboxstyle">
					<select name="sales2" id="sales2">
						<option value=""></option>
						<c:forEach items="${listuserPar}" var="listuserPar">
							<option value="${listuserPar.pkUsrId}">${listuserPar.usrName}</option>
						</c:forEach>
					</select>
				</div> <!----select---></li>
		</ul>
		<div class="btm_btn btm_bg">
			<dl>
				<dd>
					<input type="button" class="btn" onclick="updateSales()" value="确定">
				</dd>
				<dd>
					<input type="button" class="btn" onClick="clean()" value="返回">
				</dd>
			</dl>
		</div>
	</div>
	<!---弹出层--->

















</body>
</html>






